﻿using AutoMapper;
using Domain.Flow;
using MediatR;
using U.B.ErrorCode;
using U.B.Repistory;
using U.B.WriteApi.Command.RabbitBWss;

namespace U.B.WriteApi.CommandHander.RabbitBWDD
{
    public class AddrabbitsCommandHander : IRequestHandler<AddrabbitsCommand, ApiResult<object>>
    {
        public readonly IRepistory<Product> _productRepistory;
        public readonly IMapper _mapper;
        public AddrabbitsCommandHander(IRepistory<Product> productRepistory, IMapper mapper)
        {
            _productRepistory = productRepistory;
            _mapper = mapper;
        }
        /// <summary>
        /// 添加商品
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ApiResult<object>> Handle(AddrabbitsCommand request, CancellationToken cancellationToken)
        {
              ApiResult<object> result = new ApiResult<object>();
              var product = _mapper.Map<Product>(request);
              product.CreationDate = DateTime.Now;
              product.Creator = "老七";
              product.Updateor = "";
              product.Updatedate = DateTime.Now;
              product.IsDeleted=false;
              product.Full = 10;

              _productRepistory.Add(product);
              result.code = Renum.添加成功;
              result.Message = Renum.添加成功.ToString();
              return await Task.FromResult(result);
        }
    }
}
